package com.peaksport.framework.base.service;

import java.util.Date;

import com.peaksport.framework.base.entity.IEntityObject;
import com.peaksport.framework.base.entity.ObjectBaseEntity;
import com.peaksport.framework.exception.PKDevException;
import com.peaksport.framework.util.PKPublicUtils;
import com.peaksport.framework.vo.SessionInfo;
import com.peaksport.pkms.permit.entity.UserEntity;

public abstract class ObjectBaseService extends CoreBaseService {
	

	@Override
	public IEntityObject save(IEntityObject entity) {
		if (!(entity instanceof ObjectBaseEntity))
			throw PKDevException.throwException("entity实体[%s]不是[%s]基类,请开发人员检查.",entity.getClass(),ObjectBaseEntity.class.getName());
		ObjectBaseEntity objectBaseEntity = (ObjectBaseEntity)entity;
		boolean isNew = PKPublicUtils.isEmpty(objectBaseEntity.getId());
		SessionInfo contextInfo = getSessionInfo();
		UserEntity userEntity = contextInfo.getUserEntity();
		Date now = getCurrentTime();
		if (isNew) {
			objectBaseEntity.setCreator(userEntity);
			objectBaseEntity.setCreateTime(now);
		} else {
			objectBaseEntity.setLastUpdateUser(userEntity);
			objectBaseEntity.setLastUpdateTime(now);
		}
		return super.save(entity);
	}
	
	


}
